<?php
	require_once("conexion/conexion.php");
	$fecha = date("d-m-Y");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Formulario</title>
<link href="Estilos/global.css" rel="stylesheet" type="text/css" />
<link href="Estilos/local.css" rel="stylesheet" type="text/css" />
<link href="Estilos/CssTabla3.css" rel="stylesheet" type="text/css" />
<link href="Estilos/jquery.autocomplete.css" rel="stylesheet" type="text/css" />

<script src="include_js/jquery.js" type="text/javascript"></script>

<style>
.texto
{
	font-size:14px;
	margin-left:10px;
	font:Verdana, Arial, Helvetica, sans-serif; 
	color:#0066CC;
}
.borde
{
	/*border:0px solid #6593C0;*/
	border:1px solid #D3E4E5;
}
.asterisco
{
	color:#0000FF;
	font-weight:bold;
}
.radioBorde
{ 
 background:#D3E4E5;
 border:0px solid #89C0C7;
}
</style>
<script>
function EliminaPuntos(num)
{
	valor = num.replace(/\./g,'');
	return valor;
}

function validar(e)
{ 
    tecla = (document.all) ? e.keyCode : e.which; 
    if (tecla==8) return true; //Tecla de retroceso (para poder borrar) 
    patron = /\d/;
    te = String.fromCharCode(tecla); 
    return patron.test(te);  
} 

function puntitos(donde,caracter)
{
	pat = /[\*,\+,\(,\),\?,\,$,\[,\],\^]/;
	valor = donde.value;
	largo = valor.length;
	crtr = true;
	if(isNaN(caracter) || pat.test(caracter) == true)
	{
		if (pat.test(caracter)==true)
		{ 
			caracter = "\"" + caracter;
		}
		carcter = new RegExp(caracter,"g");
		valor = valor.replace(carcter,"");
		donde.value = valor;
		crtr = false;
	}
	else
	{
		var nums = new Array();
		cont = 0;
		for(m=0;m<largo;m++)
		{
			if(valor.charAt(m) == "." || valor.charAt(m) == " ")
				{continue;}
			else
			{
				nums[cont] = valor.charAt(m);
				cont++;
			}
		}
	}
	var cad1="",cad2="",tres=0;
	if(largo > 3 && crtr == true)
	{
		for (k=nums.length-1;k>=0;k--)
		{
			cad1 = nums[k];
			cad2 = cad1 + cad2;
			tres++;
			if((tres%3) == 0)
			{
				if(k!=0)
				{
					cad2 = "." + cad2;
				}
			}
		}
		donde.value = cad2;
	}
}


function BorraDatos(dato)
{
	var cadena = dato.substring(8,9);
    if(cadena=='1')
	{
		capa = document.getElementById("Cierre");
		capa.style.display = "block";
		capa1 = document.getElementById("caja");
		capa1.style.display = "none";	
	}
}

function CierreCaja()
{
	$.ajax({
            type: 'POST',
            url: 'Contabilidad/Ingresa_CierreCajaChica.php',
            data: $('#form_CierreCaja').serialize(),
            success: function(data) {
                $('#mensaje').html(data);
				BorraDatos(data);
            }
        })
}

function ActivaCierre()
{
	capa = document.getElementById("Cierre");
	capa.style.display = "block";
}
</script>
</head>
<body>
<form name="form_CierreCaja" id="form_CierreCaja" method="post">
<div class='option2'><label style="font:Verdana, Arial, Helvetica, sans-serif; color:#0066CC; font-weight:bold;">Cierre Caja Chica.</label></div>
<?php
	$con = new Conexion();
    $con2 = $con->conexionBD("fpproduccion");
	$sql1 = "select max(CajId) from caja";
	$res = mysql_query($sql1) or die ($con->error_mysql("Error en la consulta".mysql_error()));
	$cajaId = mysql_fetch_array($res);
	$con->cerrarBD();
	//echo $cajaId[0];
	
	$con = new Conexion();
    $con2 = $con->conexionBD("fpproduccion");
	$sql = "select CajEstado from caja where CajId='".$cajaId[0]."'";
    $resultado = mysql_query($sql) or die ($con->error_mysql("Error en la consulta".mysql_error()));
	$estado = mysql_fetch_array($resultado);
	$con->cerrarBD();
//	echo $estado[0];
	if($estado[0]=="ACTIVO")
	{
?>
<div id="caja" style="display:block">
<div class='groupbox'>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="uno">

<tr>
  <td class="borde" colspan="2">&nbsp;</td>
  <td class="borde">&nbsp;</td>
  <td class="borde">&nbsp;</td>
</tr>
<tr>
  <td class="borde" colspan="2"><label class="texto" style="font-weight:bold;">Cerrar Caja.</label></td>
  <td width="7%" class="borde">&nbsp;</td>
  <td width="35%" class="borde">&nbsp;</td>
  </tr>
<tr>
  <td width="26%" class="borde">&nbsp;</td>
  <td width="32%" class="borde">&nbsp;</td>
  <td class="borde">&nbsp;</td>
  <td class="borde">&nbsp;</td>
</tr>
<tr>
    <td class="borde"><label class="texto" style="margin-left:35px;">Fecha Actual:</label></td>
	  <td class="borde" colspan="3"><input style="background:#E1E1E1" type="text" name="txtFecha" value="<?php echo $fecha;?>" readonly="true" /></td></tr>
<tr>
  <td class="borde"><label class="texto" style="margin-left:35px;">Monto Apertura ($):</label></td>
  <?php
  	$con = new Conexion();
    $con2 = $con->conexionBD("fpproduccion");
    $sql = "select CajMontoIni,CajMontoAct from caja where CajEstado='".$estado[0]."'";
    $res = mysql_query($sql) or die ($con->error_mysql("Error en la consulta".mysql_error()));
	$monto = mysql_fetch_array($res);
	$con->cerrarBD();
  ?>
  <td class="borde"><input style="background:#E1E1E1" type="text" name="txtMontoApertura" readonly="true" value="<?php echo number_format ($monto[0],0,',','.');?>"/></td>
  <td class="borde">&nbsp;</td>
  <td class="borde">&nbsp;</td>
</tr>
<tr>
  <td class="borde"><label class="texto" style="margin-left:35px;">Monto Actual ($):</label></td>
  <td class="borde"><input style="background:#E1E1E1" type="text" name="txtMontoActual" value="<?php echo number_format ($monto[1],0,',','.');?>" readonly="true" /></td>
  <td class="borde">&nbsp;</td>
  <td class="borde">&nbsp;</td>
</tr>

  
  <tr>
    <td class="borde" colspan="4">&nbsp;</td>
  </tr> 
  <tr>
    <td class="borde" colspan="4"><div class="formtail"><input name="btn_Cerrar_Caja" id="btn_Cerrar_Caja" type="button" value="Cerrar Caja" onclick="CierreCaja();"/></div></td>
  </tr>
</table>
</div>
</div>
<?php }?>
<div id="Cierre" style="display:none;">
	<div class='groupbox'>
	<table width="100%" border="0" cellpadding="0" cellspacing="0" class="uno">
	<tr><td><label class="texto" style="font-weight:bold;">La Caja Chica "NO" se ha Abierto.</label></td></tr>
	</table>
	</div>
</div>
<?php
if($estado[0]!="ACTIVO")
{
	echo "<script>ActivaCierre();</script>";
}
?>
</form>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr><td><div id="mensaje"></div></td></tr>
</table>
</body>
</html>